package oracle.apps.financials.collection.listener;

import java.util.ArrayList;
import java.util.List;

import greendroid.widget.ItemAdapter;
import greendroid.widget.item.Item;
import oracle.apps.financials.collection.R;
import oracle.apps.financials.collection.po.Collector;
import oracle.apps.financials.collection.po.Customer;
import oracle.apps.financials.collection.po.TextLabelItem;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ListView;
import android.widget.PopupWindow;

public class CollectorDetailWindowListener extends BaseOnClickListener {

	private Collector collector;
	private ItemAdapter adapter;

	private CollectorPopupWindowListener collectorPopupWindowListener;

	public CollectorDetailWindowListener(Context context, CollectorPopupWindowListener collectorPopupWindowListener, Collector collector) {
		super(context, R.layout.collector_detail, null);
		this.collector = collector;
		this.collectorPopupWindowListener = collectorPopupWindowListener;
	}

	@Override
	public void onClick(View parent) {
		collectorPopupWindowListener.dismissPopupWindow();
		if (popupWindow == null) {
			initPopupWindow();
		}

		popupWindow.showAsDropDown(collectorPopupWindowListener.getLayout(), 81, -38);
	}

	public void initPopupWindow() {

		popupWindow = new PopupWindow(popupWindowView, 300, 450);
		ListView listView = (ListView) popupWindowView.findViewById(R.id.collector_detail_list);
		adapter = new ItemAdapter(this.context, getDataListItems(customer));
		listView.setAdapter(adapter);
		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
	}

	public List<Item> getDataListItems(Customer customer) {
		List<Item> items = new ArrayList<Item>();
		items.add(new TextLabelItem("Collector Name: ", collector.getCollectorName()));
		items.add(new TextLabelItem("Address: ", collector.getAddress()));
		items.add(new TextLabelItem("Email: ", collector.getEmail()));
		items.add(new TextLabelItem("Phone:  ", collector.getPhone()));
		items.add(new TextLabelItem("Language:  ", collector.getLanguage()));
		items.add(new TextLabelItem("Industry:  ", collector.getIndustry()));
		items.add(new TextLabelItem("Specialty Bucket:  ", collector.getSpeciallyBucket()));
		items.add(new TextLabelItem("TimeZone:  ", collector.getTimeZone()));
		items.add(new TextLabelItem("Availability:  ", collector.getAvailability()));
		items.add(new TextLabelItem("Region:  ", collector.getRegion()));
		return items;
	}

	public Collector getCollector() {
		return collector;
	}

	public void setCollector(Collector collector) {
		this.collector = collector;
	}
}
